package com.e2oto.seller.common.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.bumptech.glide.Glide;
import com.e2oto.seller.R;

import java.util.ArrayList;
import java.util.List;

import me.iwf.photopicker.PhotoPreview;

/**
 * Created by ZhangLiQiang on 2017/11/28.
 */

public class BannerUtils {
    /**
     * @param banner
     * @param images
     * @param context
     */
    public static void setBanner(ConvenientBanner banner, final List<String> images, final Context context) {
        banner.setPages(new CBViewHolderCreator() {
            @Override
            public Object createHolder() {
                return new Holder<String>() {
                    ImageView iv;

                    @Override
                    public View createView(Context context) {
                        iv = new ImageView(context);
                        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                        iv.setLayoutParams(params);
                        iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
                        return iv;
                    }

                    @Override
                    public void UpdateUI(Context context, int position, String data) {
                        Glide.with(context).load(data).into(iv);
                    }
                };
            }
        }, images).setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                PhotoPreview.builder()
                        .setPhotos((ArrayList<String>) images)
                        .setCurrentItem(position)
                        .setShowDeleteButton(false)
                        .start((Activity) context);
            }
        }).setPageIndicator(new int[]{R.drawable.banner_index_2, R.drawable.banner_index_1})
                .setPointViewVisible(true)
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                .startTurning(3000);
    }
}
